package com.lanou.quanttrade.member.controller;

import com.lanou.quanttrade.member.javabean.Member;
import com.lanou.quanttrade.member.service.MemberService;
import com.lanou.quanttrade.utils.annotation.RequireLogin;
import com.lanou.quanttrade.utils.javabean.RestObject;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/member")
@CrossOrigin(allowCredentials = "true",allowedHeaders = "*")  //测试阶段进行跨域，项目正式上线时，会将资源整合到static中，到时
                                                             // 候就无需跨域
public class MemberController {
    @Autowired
    private MemberService memberService;

    /**
     * 注册接口
     * @param param     用户名、密码、确认密码
     * @return
     */
    @ApiOperation("注册接口")
    @PostMapping("/register")
    public @ResponseBody RestObject register(@RequestBody Member param){
        return memberService.register(param);
    }
    /**
     * 登录接口
     * @param param     用户名、密码
     * @return
     */
    @ApiOperation("登录接口")
    @PostMapping("/login")
    public @ResponseBody RestObject login(@RequestBody Member param, @ApiIgnore HttpSession session){
        return memberService.login(param,session);
    }

    /**
     * 测试登录权限校验的接口
     * @return
     */
    @ApiOperation("测试登录权限校验的接口")
    @PostMapping("/testRequireLogin")
    @RequireLogin
    public @ResponseBody RestObject testRequireLogin(){
        return RestObject.OK("测试成功！您已登录");
    }
}
